package fun.tan90.easy.binlog.manager.handler;

import cn.hutool.json.JSONUtil;
import com.mybatisflex.core.row.Db;
import fun.tan90.easy.binlog.base.constants.EasyBinlogConstants;
import fun.tan90.easy.binlog.base.model.HeartBeat;
import fun.tan90.easy.binlog.base.strategy.AbstractExecuteStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * description TODO
 * company 铁人科技
 *
 * @author 陈浩杰
 * @date 2023/12/15 19:42
 */
@Slf4j
@Component
public class HeartBeatHandler implements AbstractExecuteStrategy<String, Void> {

    @Override
    public String mark() {
        return EasyBinlogConstants.HEARTBEAT;
    }

    @Override
    public void execute(String heartBeatJson) {
        HeartBeat heartBeat = JSONUtil.toBean(heartBeatJson, HeartBeat.class);
        Db.updateBySql("UPDATE binlog_master set heartbeat_time = ? WHERE master_code = ?", heartBeat.getTimestamp(), heartBeat.getMasterCode());
    }


}
